package kr.snaps
{
	import flash.events.TimerEvent;
	import flash.external.ExternalInterface;
	import flash.net.LocalConnection;
	import flash.utils.Timer;
	
	public class GB
	{
		// 웹용  또는 스마트 포토용인지 구분함.. 
		// WEB : 웹용, SPT : 스마트포토  
		public static var sVersionType:String = "WEB";
		
		// 채널 아이디
		public static var sChannelid:String = "";
		
		// 창 우측의 디버그 창을 없애려면, false 로 셋팅.. 
		[Bindable] 
		public static var bDebug : Boolean = false;		
		public static var bAdmin : Boolean = false;		

		public static var strViewCategoryCd : String = "";
		public static var sCategorycode:String = ""; 
		public static var sProductCode:String = "";
   
 
		public static function dispMsg(strMsg0 : Object):void
		{     
   
			//return;			 
			var dt : Date = new Date();
			var strTemp : String = ""; 
			var strMsg : String = "";
			 
			if( bDebug == false) return; 
			
			if( strMsg0 is XML)	strMsg = XML(strMsg0).toXMLString();
			else if( strMsg0 is XMLList)	strMsg = XMLList(strMsg0).toXMLString();
			else strMsg = strMsg0.toString();
				  
			strTemp = 	("00" + dt.getMinutes().toString()).substr(-2,2) + ":" + 
						("00" + dt.getSeconds().toString()).substr(-2,2) + "." + 
						(dt.getMilliseconds().toString()+"000").substr(0,3);
			 
			try {
				if(bDebug) {
					//objMain.txtDebug.text = "[ " + strTemp + " ] " +  strMsg.toString() + "\n" + objMain.txtDebug.text;
				} else {
					return;
				}				 
			}    
			catch(e:Error) {
				
			}
			
		} 
		
		public function GB()
		{ 
		  
		}
		
		private static var tMultiSkin : Timer = new Timer(500,1);
		
		public static function removeMultiSkin():void
		{
			tMultiSkin.addEventListener(TimerEvent.TIMER_COMPLETE, tMultiSkin_timer);
			tMultiSkin.start();
		}
		
		private static function tMultiSkin_timer(event:TimerEvent):void
		{
/* 			
			tMultiSkin.removeEventListener(TimerEvent.TIMER,tMultiSkin_timer);
			
			var ar : Array = objMain.cvsTop.getChildren(); 
			var n : Number;
			
 			for(n = 0; n < ar.length; n++)
			{ 
				trace("if(ar[n].className : " + ar[n].className);
				if(ar[n].className == "skin1")
				{
				}
				else
				{
					//ar[n].removeAllChildren(); 
					objMain.cvsTop.removeChild(ar[n]);	
				}
			} 
			GB.gc(); */
		}
		

		
		
		public static var numScrollPreLoad : Number = 0.2;
		
		//public static var objMain : adminIndex;
		
		public static var objSubMain : Object = null;
		
		public static var xmlData : XML = null;;
		
		public static var numViewGoodsCount : Number = 0;	
		
		// 20090310
		// 멀티 템플릿 저장용 변수
		public static var objSubSkin2 : Object = null;
		
		
		[Bindable]
		public static var numImgWidth : Number = 143;
		
		public static var strSetSkinNum : String = "";
		
		// 히스토리 메뉴 처리용
		[Bindable]	public static var strMenuCode01 : String = "";
		[Bindable]	public static var strMenuName01 : String = "";
		
		[Bindable]	public static var strMenuCode02 : String = "";
		[Bindable]	public static var strMenuName02 : String = "";
		
		[Bindable]	public static var strMenuCode03 : String = "";
		[Bindable]	public static var strMenuName03 : String = "";
		
		[Bindable]	public static var strProdCode : String = "";
		
		public static var sImgLabel : String = "";
		public static var strFtmplId : String = "";
		public static var strFtmplCode : String = "";
		
		
		public static function gc():void
		{
			try
			{
				new LocalConnection().connect("myConnect");
				new LocalConnection().connect("myConnect");
			}
			catch(e:Error)
			{
				trace("gc call");				
			}
		}
		
		public static function clearMsg():void
		{
			try { 
				if(bDebug) {
					//objMain.txtDebug.text = "";
				}				
			}
			catch(e:Error) {
				
			}			
			
		} 
		////////////////////////////////////////////////////
		// 주문하기 버튼 클릭시 스마트 포토 호출 
		////////////////////////////////////////////////////
		public static function open_OCX(bProdInfoView:Boolean, strProdCd:String, strFtmplId:String, strCategoryCd_web:String ):void
		{
			var sUrl:String 	= "/SmartPhoto/SmartPhoto.aspx?";
			var sTdata:String	= "prmprodcode="+strProdCd+"||prmtmplid="+strFtmplId+"||prmdsplcode=||categorycode="+strCategoryCd_web;
	
			// 상품이 아니라면 Tdata를 넣지 않는다.
			if(!bProdInfoView) {
				sTdata = "";
			}
			 
			// 일반사진일 경우
			// 사진인화-일반사진 : javascript:open_OCX('/SmartPhoto/SmartPhoto.aspx?ProductCode=0080010001&categorycode=05700100010001&Tdata=','SmartPhoto','width=1008,height=676')
			if(strCategoryCd_web =="05700100010001") {
				sTdata="";
				strProdCd = "0080010001";
			}
			
			// 하지만 대형사진의 일반대형 출력일 경우에는.. 넣는다.. 하드코딩
			// 대형출력-일반대형출력 : javascript:open_OCX('/SmartPhoto/SmartPhoto.aspx?ProductCode=00800800010001&categorycode=05700100060001&Tdata=prmprodcode=00800800010001||prmtmplid=t_080403_h||prmdsplcode=||categorycode=05700100060001','SmartPhoto','width=1008,height=676') 
			if(strCategoryCd_web =="05700100060001") {
				sTdata = "prmprodcode=00800800010001||prmtmplid=t_080403_h||prmdsplcode=||categorycode=05700100060001";
				strProdCd = "00800800010001";								
			} 
			
			ExternalInterface.call("open_OCX", sUrl+"ProductCode="+strProdCd+"&categorycode="+strCategoryCd_web+"&Tdata="+sTdata,
									"SmartPhoto", 'width=1008,height=676'
									);
			//Alert.show("url : " + arrSmartPhotoUrl[hlTopPosition][0] + ", title : " + arrSmartPhotoUrl[hlTopPosition][1] + ", size : "+arrSmartPhotoUrl[hlTopPosition][2])
					
								  
			trace("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");				
			trace("myMainTop strProdCd : " + strProdCd);				
			trace("myMainTop strCategoryCd_web : " + strCategoryCd_web);
			trace("myMainTop strFtmplId : " + strFtmplId);
		 
		}		  
 
		////////////////////////////////////////////////////
		// 주문하기 클릭시 장바구니 담기 호출 
		////////////////////////////////////////////////////
		public static function ProjcetCopy(projCode:String):void {
			ExternalInterface.call("ProjcetCopy", projCode);
		}

		////////////////////////////////////////////////////
		// [스마트 포토용]
		// 주문하기 버튼 클릭시  
		////////////////////////////////////////////////////
		public static function SmartPhotoCall(strCategoryCd_web:String, strProdCd:String, strFtmplId:String, sXmlPath:String, sTdata:String):void {
			ExternalInterface.call("SmartPhotoCall", strCategoryCd_web, strProdCd, strFtmplId, sXmlPath, sTdata, '');
		}	
		
		////////////////////////////////////////////////////
		// [스마트 포토용]
		// 주문하기 버튼 클릭시  
		////////////////////////////////////////////////////
		public static function aceCountLog():void {
/* 			trace(strMenuCode01+"/"+strMenuCode02+"/"+strMenuCode03);
			trace(strMenuName01+"/"+strMenuName02+"/"+strMenuName03);
			trace(strProdCode);
			trace(sImgLabel);	// 최하단 상품 이름
			trace(strFtmplId);	// 하단 상품 id
			trace(strFtmplCode);// 하단 상품 코드 .
			trace("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); */
			var sInsertUrl:String;
			sInsertUrl = strMenuName01+"/"+strMenuName02+"/"+strMenuName03+"/"+sImgLabel;
			var arrayTemp:Array = new Array();
			if(strMenuName01 != null && strMenuName01 != "") {arrayTemp.push(strMenuName01);}
			if(strMenuName02 != null && strMenuName02 != "") {arrayTemp.push(strMenuName02);}
			if(strMenuName03 != null && strMenuName03 != "") {arrayTemp.push(strMenuName03);}
			if(sImgLabel != null && sImgLabel != "") {arrayTemp.push(sImgLabel);}									
			
			var myStr:String = arrayTemp.join("/"); 
			var hostName:String = "www.snaps.co.kr/";
			trace("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
			trace("aceCounter insert : " + hostName+myStr);
			 
			ExternalInterface.call("_PL", hostName+myStr);
			
		}		
		
		
		
		
		
		
		
		
		
	/* 	
		public static function getGoodsSubject12(strCategoryCode : String = ""):String
		{
			var strRet  : String = "";
			
			if( strCategoryCode == "")
				strCategoryCode = strViewCategoryCd;
				
			switch(strCategoryCode.substr(0,14))
			{
				case "05700100010002":
					strRet = "지갑용사진";
					break;
				case "05700100010003":
					strRet = "분할사진";
					break;
				
				case "05700100040001":
					strRet = "청첩장";
					break;
				case "05700100070003":
					strRet = "핑거앨범";
					break;
					
				default:
					strRet = "그룹";
			}
			
			return strRet + ".";	
		}
		
		public static function getGoodsSubject22(strCategoryCode : String = ""):String
		{
			var strRet  : String = "";
			
			if( strCategoryCode == "")
				strCategoryCode = strViewCategoryCd;
			
			
			switch(strCategoryCode.substr(0,16))
			{
				
				case "05700100010002":
				case "0570010001000201":
					strRet = "지갑용사진[3x5] ";
					break;
					
				case "05700100010003":
				case "0570010001000301":
					strRet = "분할사진[5x7] ";
					break;
				case "0570010001000302":
					strRet = "미니 ";
					break;
				case "0570010001000303":
					strRet = "라지 ";
					break;
				
				case "05700100040001":
				case "0570010004000101":
					strRet = "포토청첩장(가로형)";
					break;
				case "0570010004000102":
					strRet = "포토청첩장(세로형)";
					break;
				case "05700100070003":
				case "0570010007000301":
					strRet = "핑거앨범";
					break;
				case "0570010007000302":
					strRet = "핑거앨범-아쿠아";
					break;
					
					
				default:
					strRet = "";
			}
			
			return strRet ;	
		}
		 */		
	}
}